﻿@{
    ViewBag.Title = "Index";
}
<h2>Profiles</h2>
<div id="ProfileListBlock"></div>
<span class="AddLink ButtonLink">Add New Profile</span>
<div id="ProfileDialog" title="" class="Hidden"></div>
<script type="text/javascript">
    $(function () {
        $("#ProfileDialog").dialog({
            autoOpen: false, width: 400, height: 500, modal: true,
            buttons: {
                "Save": function () {
                    if ($("#ProfileForm").validate().form()) {
                        $.post("/ProfileCRUD/Save",
        $("#ProfileForm").serialize(),
        function (data) {
            $("#ProfileDialog").dialog("close");
            $("#ProfileListBlock").html(data);
        });
                    }
                },
                Cancel: function () { $(this).dialog("close"); }
            }
        });
        $(".EditLink").live("click", function () {
            var id = $(this).attr("profileid");
            $("#ProfileDialog").html("")
                .dialog("option", "title", "Edit Profile")
                .load("/ProfileCRUD/Edit/" + id, function () { $("ProfileDialog").dialog("open"); });
        });
        $(".AddLink").click(function () {
            $("#ProfileDialog").html("")
                .dialog("option", "title", "Add Profile")
                .load("/ProfileCRUD/Create", function () { $("#ProfileDialog").dialog("open"); });
        });
        LoadList();
    });
    function LoadList() {
        $("#ProfileListBlock").load("/ProfileCRUD/List");
    }
</script>